package com.wframe.framework.database;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.hibernate.transform.ResultTransformer;

public class AliasToMapResultTransformer implements ResultTransformer {  
	
    private static final long serialVersionUID = -5199190581393587893L;
    
    public AliasToMapResultTransformer() {  
    }
    
    public Object transformTuple(Object[] tuple, String[] aliases) { 
        Map bean=new HashMap();
        for (int i = 0; i < aliases.length; i++) {
        	bean.put(aliases[i].toLowerCase(), jdbcDataToJava(tuple[i]));
        }
        return bean;  
    }  
    
    @SuppressWarnings({ "rawtypes", "unchecked" })  
	 public List<Map> transformList(List collection) {
	    return collection;  
	}  

    private Object jdbcDataToJava(Object obj){
    	if(obj==null)return obj;
    	if(obj instanceof java.lang.Short){
    		return Integer.parseInt(obj.toString());
    	}else return obj;
    }

}
